package org.com.coolfish.common.database.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.com.coolfish.common.database.entity.KuyuAddPackage;
import org.com.coolfish.common.database.repository.KuyuAddPackageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
public class KuyuAddPackageService {
    @Autowired
    private KuyuAddPackageRepository repository;

    @Transactional
    public void delete(Integer id) {
        repository.deleteById(id);
    }

    @Transactional(readOnly = true)
    public KuyuAddPackage get(Integer id) {
        return repository.getOne(id);
    }

    @Transactional
    public void save(KuyuAddPackage kuyu) {
    	log.info("插入数据为:{}"+kuyu.toString());
    		  repository.saveAndFlush(kuyu);
     }

    @Transactional(readOnly = true)
    public List<KuyuAddPackage> findAll() {
        return repository.findAll();
    }

    @Transactional(readOnly = true)
    public List<KuyuAddPackage> findFlashObject(Integer cardId) {

        return repository.findFlashObject(cardId);
    }

    @Transactional
    public void flashSilentTime(Date starttime ,Date endtime, Integer id) {
        repository.flashSlientTime(starttime,endtime, id);

    }

    @Transactional(readOnly = true)
    public List<KuyuAddPackage> findMonthlyHaveSumFlow() {

        return repository.findMonthlyHaveSumFlow();
    }

    @Transactional(readOnly = true)
    public BigDecimal findMonthlySumFlows(Integer cardid) {

        return repository.findMonthlySumFlows(cardid);
    }

    @Transactional(readOnly = true)
    public List<KuyuAddPackage> findEndTimeError() {
        return repository.findEndTimeError( );

    }
    @Transactional
    public void flushEndTime(Integer id, Date endTime) {
       repository.flushEndTime(id,endTime);
        
    }
    public List<KuyuAddPackage> findStopCorrelation(Integer id,Date starttime,Date endtime){
    	return repository.findStopCorrelation(id,starttime,endtime);
    }
    
    public KuyuAddPackage findMonthlySumFlowsAndUseflow(Integer id) {
    	return repository.findMonthlySumFlowsAndUseflow(id);
    }
    
    public KuyuAddPackage findAddPackgePropert(Integer id) {
    	return repository.findAddPackgePropert(id);
    }
    @Transactional
    public void updateStartTime(Integer id,Date starttime){
    	repository.updateStartTime(id,starttime);
    }
    @Transactional
    public void queryUnusePackageAndChangeStatus(Date fisttime,Date endtime){
    	repository.queryUnusePackageAndChangeStatus(fisttime,endtime);
    }
   /* @Transactional
    public void queryToopenPackageAndChangeType(Date begintime){
    	repository.queryToopenPackageAndChangeType(begintime);
    }*/
    @Transactional
    public List<KuyuAddPackage> queryToopenPackage(Date begintime){
    	return repository.queryToopenPackage(begintime);
    }
    @Transactional
    public void changeType(Integer id){
    	 repository.changeType(id);
    }
    @Transactional
    public List<KuyuAddPackage> findOperatorName(){
    	return repository.findOperatorName();
    }
  /*  @Transactional
    public List<KuyuAddPackage> findAllPackage(Integer cardid){
    	return repository.findAllPackage(cardid);
    }*/
    
    
    /*@Transactional
    public void addPackagePush(){
    	repository.addPackagePush();
    }*/
    /*@Transactional
    public void insertAddPackage() {
    	repository.insertAddPackage();
    }*/
    /*@Transactional
    public void saveEmptyPackage() {
    	repository.saveEmptyPackage();
    }*/
   
   /* public void savePackage(KuyuAddPackage kuyu) {
    	repository.savePackage(
    			kuyu.getAddtime(),
    			kuyu.getBeapiflow(),
    			kuyu.getCard(),
    			kuyu.getCardId(),
    			kuyu.getDid(),
    			kuyu.getFinalprice(),
    			kuyu.getInuse(),
    			kuyu.getLeftflow(),
    			kuyu.getOperatorName(),
    			kuyu.getPackageid(),
    			kuyu.getPid(),
    			kuyu.getPkg(),
    			kuyu.getProfit(),
    			kuyu.getRemarks(),
    			kuyu.getResult(),
    			kuyu.getSerialNumber(),
    			kuyu.getSource(),
    			kuyu.getStarttime(),
    			kuyu.getStatus(),
    			kuyu.getSumflow(),
    			kuyu.getType(),
    			kuyu.getUid(),
    			kuyu.getUseflow()
    			);
    }*/
    
    public KuyuAddPackage findOrderByCardIdAndPackageid(Integer cardId,Integer packageid) {
    	return repository.findOrderByCardIdAndPackageid(cardId,packageid);
    }
    	
    
   
}
